/*-------------------------------------------------
   EDRLIB.C -- Easy Drawing Routine Library module

               (c) Charles Petzold, 1998
  -------------------------------------------------*/
#include <stdio.h>
#include <tchar.h>
#include  <Windows.h>
#include "hook.h"
/*Gloable variable*/
HINSTANCE g_hinstDll = NULL;
HHOOK g_hhook = NULL;
DWORD g_dwClientThreadID = 0;// app thread
/*Gloable variable*/ 
int WINAPI DllMain (HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved)
{
	g_hinstDll = hInstance;
     return TRUE ;
}
LRESULT CALLBACK CallWndProc(
					int nCode,      // hook code
					WPARAM wParam,  // current-process flag
					LPARAM lParam   // address of structure with message data
								)
{
	CWPSTRUCT* p = (CWPSTRUCT*)lParam;
	char  szBuffer[20];
	if(p->message == WM_COMMAND /*&& 1148 == LOWORD(p->wParam)*/)
	{
		_stprintf(szBuffer,"%d",LOWORD(p->wParam));
		 MessageBox(NULL,"WM_COOMND",szBuffer,MB_OK);
		return 1;
	}
	return CallNextHookEx(g_hhook,nCode,wParam,lParam);

}
EXPORT BOOL WINAPI SetMyHook(DWORD dwThreadId)
{
	if(dwThreadId != 0)
	{
		g_dwClientThreadID = GetCurrentThreadId();//app thread 
		g_hhook = SetWindowsHookEx(WH_CALLWNDPROC, CallWndProc,g_hinstDll,dwThreadId);
		//PostThreadMessage(dwThreadId, WM_NULL, 0, 0);
	}
	else
		UnhookWindowsHookEx(g_hhook);
		return TRUE;
}